//
//  GWReadersView.swift
//  GhostWorld
//
//  Created by Kam on 2018/4/5.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

class GWReadersView: UIView {
  
  // MARK: - IBOutlets
  
  @IBOutlet weak var stackView: UIStackView!
  
  // MARK: - Private vars
  
  
  
  // MARK: - Private methods
  
  
  
  // MARK: - Public vars
  
  
  
  // MARK: - Lifecycle
  

  
  // MARK: - IBActions
  
  
  
  // MARK: - Public methods
  
  func prepare(readers: [Reader]) {
    subviews.forEach {
      if type(of: $0) == PersonView.self {
        $0.removeFromSuperview()
      }
    }
    for (index, reader) in readers.enumerated() {
      if index < 3 {
        let item: PersonView = .fromNib()
        item.prepare(person: reader)
        stackView.addArrangedSubview(item)
        
        item.snp.makeConstraints { maker in
          maker.width.equalTo(PersonView.defaultWidth)
          maker.height.equalTo(PersonView.defaultHeight)
        }
      } else {
        break
      }
    }
  }
}

extension GWReadersView {
  static var defaultHeight: CGFloat = PersonView.defaultHeight
}
